---OOSE SoSe 2011 Aufgabe 3
--@author Oleg Mayevskiy <mayevskiy.oleg@googlemail.com> (233197)
require('Game')

function _checkValue(value, expected)
  if value ~= expected then
    error("Value: "..tostring(value)..". Expected value: "..tostring(expected)..".")
  end
end

function _checkFalse(value)
  if value then
    error("Value: "..tostring(value)..". Expected value: false (or equal).")
  end
end

function _checkTrue(value)
  if not value then
    error("Value: "..tostring(value)..". Expected value: true (or equal).")
  end
end


collection = GameCollection:create()


-- Start eines TicTacToe - Spiels ueber Methodenaufrufe
game = collection:startSilent("TicTacToe")
--game:print()
nextplayer, finished = game:move(1)
nextplayer, finished = game:move(2)
nextplayer, finished = game:move(3)
nextplayer, finished = game:move(4)
nextplayer, finished = game:move(5)
nextplayer, finished = game:move(6)
game:print()
nextplayer, finished = game:move(7)
game:print()
nextplayer, finished = game:move(8)
nextplayer, finished = game:move(9)
--nextplayer, finished = game:move(0)
--game:print()
--_checkValue(nextplayer, nil)
--_checkFalse(finished)

_checkValue(nextplayer, "O")
_checkFalse(finished)
game:print()
-- Neustarten des TicTacToe - Spiels
game:restart()
game:print()
nextplayer, finished = game:move(2)
nextplayer, finished = game:move(3)
_checkValue(nextplayer, "X")
_checkFalse(finished)
nextplayer, finished = game:move(1)
game:move(6)
-- Ausfuehren eines ungueltigen Zugs mit Zugwiederholung
nextplayer, finished = game:move(1)
_checkValue(nextplayer, "X")
_checkFalse(finished)
game:move(7)
game:move(8)
nextplayer, finished = game:move(4)
game:print()
_checkValue(nextplayer, "X")
_checkTrue(finished)

-- Start eines interaktiven Spieles ueber die Konsole
collection:startInteractive()


